package modele.beanEntity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Calendar;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import sun.util.resources.CalendarData_fr;

public class User implements Serializable {
		private Integer id;
		private String firstName;
		private String lastName;
		private Integer age;
		private String email;
		private String login;
		private String password;
		private Timestamp lastConnection;
		private Integer lastConnectionDuration;
		private String role;
		private String other1;
		private String other2;
		private String other3;
		private String img="picture1";
		
		public static String ADMIN_ROLE="ADMIN";
		public static String USER_ROLE="USER";
		
		public User() {
			super();
			this.id = 0;
			this.firstName = "";
			this.lastName = "";
			this.age = 0;
			this.email = "";
			this.login = "";
			this.password = "";
			this.lastConnection = null;
			this.lastConnectionDuration = 0;
			this.role = User.USER_ROLE;
			this.other1 = "";
			this.other2 = "";
			this.other3 = "";
			this.img = "";
		}
		
		public User(Integer id, String firstName, String lastName, Integer age,
				String email, String login, String password, Timestamp lastConnection,
				Integer lastConnectionDuration, String role, String other1,
				String other2, String other3, String img) {
			super();
			this.id = id;
			this.firstName = firstName;
			this.lastName = lastName;
			this.age = age;
			this.email = email;
			this.login = login;
			this.password = password;
			this.lastConnection = lastConnection;
			this.lastConnectionDuration = lastConnectionDuration;
			this.role = role;
			this.other1 = other1;
			this.other2 = other2;
			this.other3 = other3;
			this.img = img;
		}
		
		
		public Integer getId() {
			return id;
		}
		public void setId(Integer id) {
			this.id = id;
		}
		public String getFirstName() {
			return firstName;
		}
		public void setFirstName(String firstName) {
			this.firstName = firstName;
		}
		public String getLastName() {
			return lastName;
		}
		public void setLastName(String lastName) {
			this.lastName = lastName;
		}
		public Integer getAge() {
			return age;
		}
		public void setAge(Integer age) {
			this.age = age;
		}
		public String getEmail() {
			return email;
		}
		public void setEmail(String email) {
			this.email = email;
		}
		public String getLogin() {
			return login;
		}
		public void setLogin(String login) {
			this.login = login;
		}
		public String getPassword() {
			return password;
		}
		public void setPassword(String password) {
			this.password = password;
		}
		public Timestamp getLastConnection() {
			return lastConnection;
		}
		public void setLastConnection(Timestamp lastConnection) {
			this.lastConnection = lastConnection;
		}
		public Integer getLastConnectionDuration() {
			return lastConnectionDuration;
		}
		public void setLastConnectionDuration(Integer lastConnectionDuration) {
			this.lastConnectionDuration = lastConnectionDuration;
		}
		public String getRole() {
			return role;
		}
		public void setRole(String role) {
			this.role = role;
		}
		public String getOther1() {
			return other1;
		}
		public void setOther1(String other1) {
			this.other1 = other1;
		}
		public String getOther2() {
			return other2;
		}
		public void setOther2(String other2) {
			this.other2 = other2;
		}
		public String getOther3() {
			return other3;
		}
		public void setOther3(String other3) {
			this.other3 = other3;
		}
		public String getImg() {
			return img;
		}
		public void setImg(String img) {
			this.img = img;
		}

		public boolean isAdmin(){
			return this.role.toUpperCase().equals(User.ADMIN_ROLE);
		}
		
		public void setAdmin(boolean b){
			if(b){
				this.role = User.ADMIN_ROLE;
			}else{
				this.role = User.USER_ROLE;
			}
		}
		
		public boolean getIsAdmin(){
			return this.isAdmin();
		}
		
		public void setIsAdmin(boolean b){
			this.setAdmin(b);
		}

		public String getLastConnectionString(){
			if(lastConnection == null){
				return "";
			}
			return lastConnection.toString().substring(0, 19);
		}
		@Override
		public String toString() {
			return "User [id=" + id + ", firstName=" + firstName
					+ ", lastName=" + lastName + ", age=" + age + ", email="
					+ email + ", login=" + login + ", password=" + password
					+ ", lastConnection=" + lastConnection
					+ ", lastConnectionDuration=" + lastConnectionDuration
					+ ", role=" + role + ", other1=" + other1 + ", other2="
					+ other2 + ", other3=" + other3 + ", img=" + img + "]";
		}
}
